<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="房屋类型:">
          <el-select v-model="listPram.houseType" placeholder="全部" style="width: 150px">
            <el-option
                v-for="item in houseTypeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.label">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="房屋状态:">
          <el-select v-model="listPram.houseStatus" placeholder="全部" style="width: 150px">
            <el-option
                v-for="item in houseStatusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.label">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="房屋:">
          <el-input v-model="listPram.houseKeyword" placeholder="请输入租赁证编号、地址关键词" clearable style="width: 250px"/>
        </el-form-item>
        <el-form-item label="承租人:">
          <el-input v-model="listPram.lesseeKeyword" placeholder="请输入姓名、身份证号、手机号关键词" clearable style="width: 250px"/>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        <el-form-item class="el-form-item-align-right">
          <el-button
              icon="el-icon-upload2"
              @click="handleExport('multi')"
              type="primary" size="mini" v-has-permi="['admin:house:information:export']">
            批量导出
          </el-button>
        </el-form-item>
        <el-form-item class="el-form-item-align-right">
          <el-button icon="el-icon-upload2" size="mini" type="primary" v-has-permi="['admin:house:information:import']">批量导入
          </el-button>
        </el-form-item>
        <el-form-item class="el-form-item-align-right">
          <el-button icon="el-icon-circle-plus-outline" size="mini" type="primary"
                     @click="openEdit(0)" v-has-permi="['admin:house:information:save']">新增
          </el-button>
        </el-form-item>


      </el-form>
      <el-table :data="listData.records" size="small"
                :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column align="center" label="ID" prop="id" width="60"></el-table-column>
        <el-table-column align="center" label="类型" prop="houseType" width="100"/>
        <el-table-column align="center" label="租赁证编号" prop="leaseCertificateNumber" width="100"/>
        <el-table-column label="地址" header-align="center">
          <el-table-column align="center" label="片区" prop="areaName" width="100"/>
          <el-table-column align="center" label="街（巷、路）" prop="streetName" min-width="100"/>
          <el-table-column align="center" label="号（楼、院）" prop="courtyardNumber" width="100"/>
          <el-table-column align="center" label="单元" prop="unitNumber" width="80"/>
          <el-table-column align="center" label="楼号" prop="buildingNumber" width="80"/>
          <el-table-column align="center" label="房号" prop="roomNumber" width="80"/>
        </el-table-column>
        <el-table-column align="center" label="建筑面积（㎡）" prop="buildingArea" width="100"/>
        <el-table-column align="center" label="使用面积（㎡）" prop="usableArea" width="100"/>
        <el-table-column align="center" label="状态" width="100">
          <template slot-scope="scope">
            <span :style="{ color: scope.row.houseStatus === '已租' ? 'green' : 'red' }">
              {{ scope.row.houseStatus }}
            </span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="320" fixed="right">
          <template slot-scope="scope">
            <el-button icon="el-icon-s-opportunity" size="mini" type="primary" @click="openEdit(1,scope.row)"
                       v-has-permi="['admin:house:information:save']">一站式总览
            </el-button>
            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openEdit(1,scope.row)"
                       v-has-permi="['admin:house:information:save']">编辑
            </el-button>
            <el-button icon="el-icon-delete" size="mini" type="danger" @click="handlerDelete(scope.row.id)"
                       v-has-permi="['admin:house:information:delete']">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[10,20,40,60,80,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listData.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
        :visible.sync="editDialog.visible"
        :title="editDialog.isCreate === 0? '编辑':'新增'"
        destroy-on-close
        :close-on-click-modal="false"
        top="50px"
        width="1200px">
      <edit
          v-if="editDialog.visible"
          :is-create="editDialog.isCreate"
          :edit-data="editDialog.editDate"
          @hideEditDialog="hideEditDialog"
          ref="editForm"
      />
    </el-dialog>
  </div>
</template>

<script>
import edit from './edit.vue'
import {list} from "@/api/house";
import {checkPermi} from "@/utils/permission";
import {exportMultiColumn} from "@/api/export";

export default {
  components: {edit},
  data() {
    return {
      listData: {
        records: [], total: 0
      },
      listPram: {
        page: 1,
        limit: 10,
        houseKeyword: '',
        houseStatus: '',
        houseType: '',
        lesseeKeyword: '',
      },
      editDialog: {
        visible: false,
        isCreate: 0, // 0=创建，1=编辑
        editDate: {},
      },
      tableLoading: false,
      houseTypeOptions: [{
        value: '1',
        label: '直管公房'
      }, {
        value: '2',
        label: '廉租房'
      }, {
        value: '3',
        label: '公租房'
      }, {
        value: '4',
        label: '经济适用房'
      }, {
        value: '5',
        label: '过渡房'
      }, {
        value: '6',
        label: '代管产'
      }, {
        value: '7',
        label: '廉租住房'
      }],
      houseStatusOptions: [{
        value: '1',
        label: '空'
      }, {
        value: '2',
        label: '已租'
      }, {
        value: '3',
        label: '维修'
      }],
    }
  },
  mounted() {
    this.imageUrl = process.env.VUE_APP_IMAGE_URL
    this.getList()
  },
  methods: {
    checkPermi,
    getList() {
      this.tableLoading = true
      list(this.listPram).then(res => {
        this.listData = res;
      }).finally(() => {
      })
      this.tableLoading = false;
    },
    openEdit(isCreate, editDate) {
      this.editDialog.editDate = editDate;
      this.editDialog.isCreate = isCreate;
      this.editDialog.visible = true
    },
    handlerDelete(id) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading = this.$loading({text: '删除中', background: 'rgba(255,255,255,.5)'})
        list(id).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(() => {
          loading.close()
        })
      })
    },
    handleExport(){
      exportMultiColumn().then(() => {
      }).finally(() => {
      })
    },
    hideEditDialog() {
      this.editDialog.visible = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    resetQuery() {
      this.listPram.houseKeyword = '';
      this.listPram.houseStatus = '';
      this.listPram.keyhouseTypeword = '';
      this.listPram.lesseeKeyword = '';
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
